﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
namespace SQT.tracnghiem.Ajax.ASP.Staff
{
    public partial class working : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string edited = Request.Form["edited"];
            string[] split = new string[edited.Split(',').Length];
            split = edited.Split(',');
            for (int i = 0; i < split.Length - 1; i++)
            {
                string[] split1 = new string[split[i].Split('_').Length];
                split1 = split[i].Split('_');
                int week = int.Parse(split1[0]);
                int id = int.Parse(split1[1]);
                int manager = int.Parse(split1[2]);
                string[] split2 = new string[8];
                split2 = split1[3].Split('|');
                string time = null, mon = null, tue = null, thu = null, wed = null, fri = null, sat = null, sun = null;
                //if (split2[0].Trim() != "")
                time = split2[0].Trim();
                //if (split2[1].Trim() != "")
                mon = split2[1].Trim();
                //if (split2[2].Trim() != "")
                tue = split2[2].Trim();
                //if (split2[3].Trim() != "")
                wed = split2[3].Trim();
                //if (split2[4].Trim() != "")
                thu = split2[4].Trim();
                //if (split2[5].Trim() != "")
                fri = split2[5].Trim();
                //if (split2[6].Trim() != "")
                sat = split2[6].Trim();
                //if (split2[7].Trim() != "")
                sun = split2[7].Trim();
                if (id != 0)
                {
                    new TblWorkingController().Update(id, week, manager, time, mon, tue, wed, thu, fri, sat, sun);
                }
                else
                {
                    new TblWorkingController().Insert(week, manager, time, mon, tue, wed, thu, fri, sat, sun);
                }

                var get_week = new TblWeekController().FetchAll().Where(x => x.Id == week).Single();
                new TblWeekController().Update(get_week.Id, null, null, null, DateTime.Now);
            }

        }
    }
}